import { WatchStopHandle } from "vue";


export enum MsgCodes {
    /// <summary>
    /// 结构原理消息段  20000 - 29999
    /// </summary>
    //获取结构树目录
    STRUCTURE_GET_TREE_MENU = 20000,
    //获取结构树目录节点数据
    STRUCTURE_GET_TREE_MENU_NODE = 20001,
    //获取所有任务
    STRUCTURE_GET_ALL_TASK = 20002,
    //设置任务内容
    STRUCTURE_SET_TASK = 20003,
    //获取任务目录数据
    STRUCTURE_GET_TASK_MENU = 20004,
    //获取操作数据
    STRUCTURE_GET_CURRENT_TASK = 20005,
    //更新操作数据
    STRUCTURE_UPDATE_CURRENT_TASK = 20006,
    //提交操作
    STRUCTURE_SUBMIT_CURRENT_TASK = 20007,
    //提交
    STRUCTURE_SUBMIT = 20008,
    //获取评价
    STRUCTURE_GET_APPRAISE = 20009,
    //设置模式
    STRUCTURE_SET_MODEL = 20010,
    // 获取视角
    STRUCTURE_GET_VIEW = 20011,
    // 刷新重置训练题目
    STRUCTURE_RESET = 20012,
    //获取服务端可连接设备
    SERVER_GET = 10001,
    //连接服务端设备
    SERVER_CONNECT = 10002,
    //断开服务端设备
    SERVER_DISCONNECT = 10003,
    //获取
    CONFIG_GET = 10004,
    //保存
    CONFIG_SAVE = 10005,
}



/**
 * 消息码
 */
export default class MessageCode {
    private static instance: MessageCode = new MessageCode();
    /**
     * 消息码
     */
    public static get Default(): MessageCode {
        return this.instance;
    }

    constructor() {
        window.addEventListener('unload', this.Dispose.bind(this));
    }

    Dispose() {
        window.removeEventListener('unload', this.Dispose);

        for (const watchStopHandle of this.watchStopHandles) {
            watchStopHandle();
        }
        this.watchStopHandles.clear();
    }


    public MsgCodesList = MsgCodes

    private watchStopHandles: Array<WatchStopHandle> = [];

    public async Awake(): Promise<void> {
    }

    public async Destroy(): Promise<void> {
    }
}